package com.nightsoul.ehcache.test;

import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.CacheManagerBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;


public class JavaConfiguration {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
				.withCache("preConfigured", CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Object.class, 
						ResourcePoolsBuilder.heap(100).build())).build(true);
		
		Cache<String, Object> cache = cacheManager.getCache("preConfigured", String.class, Object.class);
		cache.put("name", "zhangsan");
		
		System.out.println(cache.get("name"));
		
		Cache<String, Object> myCache = cacheManager.createCache("myCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Object.class, 
				ResourcePoolsBuilder.heap(100).build()));
		myCache.put("age", 45);
		System.out.println(myCache.get("age"));
		
		cacheManager.close();
	}

}
